﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using RMCharGen.Character; 

namespace RMCharGen
{
    internal partial class Statistics : Form
    {
        internal delegate void CharacterUpdated();

        private CharacterSheet _currentCharacter;
        private CharacterSheet _originalCharacter;

        private CharacterUpdated _callback;

        private void AcceptCurrent()
        {
            this._originalCharacter.Statistics[StatisticType.AG] = this._currentCharacter.Statistics[StatisticType.AG];
            this._originalCharacter.Statistics[StatisticType.CO] = this._currentCharacter.Statistics[StatisticType.CO];
            this._originalCharacter.Statistics[StatisticType.EM] = this._currentCharacter.Statistics[StatisticType.EM];
            this._originalCharacter.Statistics[StatisticType.In] = this._currentCharacter.Statistics[StatisticType.In];
            this._originalCharacter.Statistics[StatisticType.Me] = this._currentCharacter.Statistics[StatisticType.Me];
            this._originalCharacter.Statistics[StatisticType.Pr] = this._currentCharacter.Statistics[StatisticType.Pr];
            this._originalCharacter.Statistics[StatisticType.Qu] = this._currentCharacter.Statistics[StatisticType.Qu];
            this._originalCharacter.Statistics[StatisticType.Re] = this._currentCharacter.Statistics[StatisticType.Re];
            this._originalCharacter.Statistics[StatisticType.SD] = this._currentCharacter.Statistics[StatisticType.SD];
            this._originalCharacter.Statistics[StatisticType.St] = this._currentCharacter.Statistics[StatisticType.St];
        }

        private void CloneCharacter()
        {
            this._currentCharacter = new CharacterSheet();
            this._currentCharacter.Statistics[StatisticType.AG] = this._originalCharacter.Statistics[StatisticType.AG];
            this._currentCharacter.Statistics[StatisticType.CO] = this._originalCharacter.Statistics[StatisticType.CO];
            this._currentCharacter.Statistics[StatisticType.EM] = this._originalCharacter.Statistics[StatisticType.EM];
            this._currentCharacter.Statistics[StatisticType.In] = this._originalCharacter.Statistics[StatisticType.In];
            this._currentCharacter.Statistics[StatisticType.Me] = this._originalCharacter.Statistics[StatisticType.Me];
            this._currentCharacter.Statistics[StatisticType.Pr] = this._originalCharacter.Statistics[StatisticType.Pr];
            this._currentCharacter.Statistics[StatisticType.Qu] = this._originalCharacter.Statistics[StatisticType.Qu];
            this._currentCharacter.Statistics[StatisticType.Re] = this._originalCharacter.Statistics[StatisticType.Re];
            this._currentCharacter.Statistics[StatisticType.SD] = this._originalCharacter.Statistics[StatisticType.SD];
            this._currentCharacter.Statistics[StatisticType.St] = this._originalCharacter.Statistics[StatisticType.St];
        }

        internal Statistics(CharacterSheet character,
                            CharacterUpdated callback)
        {
            InitializeComponent();
            this._callback = callback;
            this._originalCharacter = character;
            CloneCharacter();
            this.StatisticsEditGrid.AllowEdits = true;
            this.StatisticsEditGrid.Character = this._currentCharacter;
        }

        
        private void Statistics_Load(object sender, EventArgs e)
        {
            this.StatisticsEditGrid.Bind();
        }

        private void Accept_Click(object sender, EventArgs e)
        {
            AcceptCurrent();
            this._callback.Invoke();
            this.Close();
        }

        private void Cancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

    }
}
